<?php 

require_once ('./View/RegisterView.php');
require_once ('./Model/RegisterHandler.php');
require_once ('./Model/LoginHandler.php'); 

//TODO: Dependency injection på Databas till
class RegisterController
{
	public function DoControll($database)
	{
		$outPut = "";
		$messegeid = 0;
		$messege = "";
		// hämtar databas instacer

		$regView = new RegisterView();
		$regHandler = new RegisterHandler($database);
		$logHandler = new LoginHandler($database);
		// har användaren tryckt på login knappen 
		if ($regView->TriedToRegister())
		{
			$messegeid = $regHandler->RegisterUser($regView->PostUserName(), $regView->PostPassword(),$regView->PostSamePass());
			if ($messegeid == RegisterHandler::ALL_PASS_WRONG)
			{
				$messege .= $regView->Message(RegisterView::ALL_PASS_WRONG);
			}
		if ($messegeid == RegisterHandler::EMPTY_FIELD)
			{
				$messege .= $regView->Message(RegisterView::EMPTY_FIELD);
			}
		if ($messegeid == RegisterHandler::USER_USED)
			{
				$messege .= $regView->Message(RegisterView::USER_USED);
			}
		if ($messegeid == RegisterHandler::WRONG_PASS_FORMAT)
			{
				$messege .= $regView->Message(RegisterView::WRONG_PASS_FORMAT);
			}
		if ($messegeid == RegisterHandler::REG_ACCEPT)
			{
				$messege .= $regView->Message(RegisterView::REG_ACCEPT);
			}

		}
		$outPut .= $regView->DoRegisterBox();
		$outPut .= $messege;
		return $outPut;
	}
}
